package com.business.controller.interfaced;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.business.service.interfaced.LogisticsInManager;
import com.honour.service.interfaced.OrderManager;
import com.system.controller.base.BaseController;
import com.system.util.AppUtil;
import com.system.util.DateUtil;
import com.system.util.PageData;
import com.system.util.Tools;

/**
 * 物流接口
 * @Function 
 * @Author zhaozhenhua
 * @Date 2018年2月26日
 */

@Controller
@RequestMapping("logistics")
public class LogisticsInController extends BaseController{
	
	@Resource(name="logisticsInService")
	private LogisticsInManager logisticsInService;
	
	@Resource(name = "orderService")
	private OrderManager orderService;
	
	
	
	/**
	 * 后台发货
	  * @Description
	  * @Author zhaozhenhua
	  * @date   2018年2月26日
	  * @param pd
	  * @return
	  * @throws Exception
	 */
	@RequestMapping("addlogistics")
	@ResponseBody
	public Object addLogistics(){
		logBefore(logger, "后台发货 ");
		Map<String,Object> map = new HashMap<String,Object>();
		PageData pd = new PageData();
		pd = this.getPageData();
		String result = "00";
		try{
			if(Tools.checkKey("ADDLOGISTICS", pd.getString("FKEY"))){	//检验请求key值是否合法
				if(AppUtil.checkParam("addLogistics", pd)){	//检查参数
					pd.put("LOGISTICS_ID", this.getSnowId());
					pd.put("DILIVERY_TIME", DateUtil.getTime());
					logisticsInService.addLogistics(pd);
					//发货后修改订单项的状态
					List<PageData> orderItems = orderService.getOrderItemById(pd);
					for (PageData p : orderItems) {
						p.put("ORDERSTATUS", "待收货");
						orderService.updateOrderStatus(p);
					}
					result = "01";
				}else {
					result = "03";
				}
			}else{
				result = "05";
			}
		}catch (Exception e){
			logger.error(e.toString(), e);
		}finally{
			map.put("result", result);
			logAfter(logger);
		}
		return AppUtil.returnObject(new PageData(), map);
	}
	

}
